package com.sg.plmadapter.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bson.types.ObjectId;

import com.mobnut.db.model.AccountInfo;
import com.mobnut.db.model.IContext;
import com.mobnut.db.model.ModelService;
import com.sg.business.model.Document;

public class LinkDelivery extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse resp)
			throws ServletException, IOException {
		String id = request.getParameter("id"); //$NON-NLS-1$
		ObjectId _id = new ObjectId(id);
		final Document document = ModelService.createModelObject(
				Document.class, _id);
		IContext context = new IContext() {
			@Override
			public String getPartId() {
				return null;
			}

			@Override
			public AccountInfo getAccountInfo() {
				return document.get_caccount();
			}
		};
		try {
			document.doAddToBindingWorkDeliverable(context);
		} catch (Exception e) {
		}
	}
}
